module.exports = class extends think.Model {
    async info (id) {
      const db = think.mongoose('mongo/task')
      let _id = think.objId(id)
      let task = await db.findOne({_id})
      return task
    }
    async add (data) {
      const db = think.mongoose('mongo/task')
      let doc = new db(data)
      await doc.save()
    }
    async edit (data) {
      const db = think.mongoose('mongo/task')
      await db.updateOne({_id: think.objId(data._id)}, data)
    }
    async list (page, num, json) {
      page = parseInt(page || 1)
      num = parseInt(num || 15)
      json = json || {}

      const db = think.mongoose('mongo/task')
      let result = await db.find(json).sort({_id: -1}).skip((page-1) * num).limit(num) // 获取列表

      return result
    }
    async count (json) {
      json = json || {}
      const db = think.mongoose('mongo/task')
      let count = await db.find(json).count()
      return count
    }
};
